package com.zjsd.sqeybusiness.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.zjsd.sqeybusiness.domain.SysArea;
import com.zjsd.sqeybusiness.service.ISysAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 省市区县字典Controller
 *
 * @author jerri
 * @date 2024-05-21
 */
@RestController
@RequestMapping("/sqeyerp/sysarea")
public class SysAreaController extends BaseController
{
    @Autowired
    private ISysAreaService sysAreaService;

    /**
     * 查询省市区县字典列表
     */
    //@PreAuthorize("@ss.hasPermi('sqeyerp:sysarea:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysArea sysArea)
    {
        startPage();
        List<SysArea> list = sysAreaService.selectSysAreaList(sysArea);
        return getDataTable(list);
    }

    /**
     * 导出省市区县字典列表
     */
    //@PreAuthorize("@ss.hasPermi('sqeyerp:sysarea:export')")
    @Log(title = "导出省市区县字典", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysArea sysArea)
    {
        List<SysArea> list = sysAreaService.selectSysAreaList(sysArea);
        ExcelUtil<SysArea> util = new ExcelUtil<SysArea>(SysArea.class);
        return util.exportExcel(list, "sysarea");
    }

    /**
     * 获取省市区县字典详细信息
     */
    //@PreAuthorize("@ss.hasPermi('sqeyerp:sysarea:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysAreaService.selectSysAreaById(id));
    }

    /**
     * 新增省市区县字典
     */
    //@PreAuthorize("@ss.hasPermi('sqeyerp:sysarea:add')")
    @Log(title = "新增省市区县字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysArea sysArea)
    {
        return toAjax(sysAreaService.insertSysArea(sysArea));
    }

    /**
     * 修改省市区县字典
     */
    //@PreAuthorize("@ss.hasPermi('sqeyerp:sysarea:edit')")
    @Log(title = "修改省市区县字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysArea sysArea)
    {
        return toAjax(sysAreaService.updateSysArea(sysArea));
    }

    /**
     * 删除省市区县字典
     */
    //@PreAuthorize("@ss.hasPermi('sqeyerp:sysarea:remove')")
    @Log(title = "删除省市区县字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysAreaService.deleteSysAreaByIds(ids));
    }
}
